﻿Public Class SuperRadioButton
    Inherits Windows.Forms.RadioButton

    '# controllare l'utilizzo di questa proprieta
    Public Property EnableDeCheck As Boolean = False


    Private Sub SuperRadioButton_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.CheckedChanged
        Dim opt As SuperRadioButton = CType(sender, SuperRadioButton)

        If opt.Checked Then
            opt.ForeColor = Drawing.Color.Red
        Else
            opt.ForeColor = Drawing.Color.LightGray
        End If
    End Sub

    Private Sub SuperRadioButton_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        Select Case e.KeyCode
            Case Windows.Forms.Keys.Return
                e.Handled = True
                Windows.Forms.SendKeys.Send("{TAB}")
                e.SuppressKeyPress = True
        End Select
    End Sub

    Private Sub SuperRadioButton_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
        If Not EnableDeCheck Then Return
        If e.Button = Windows.Forms.MouseButtons.Right Then
            If Me.Checked Then
                Me.Checked = False
            End If
        End If
    End Sub
End Class
